//
//  RHMessageViewController.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/7/5.
//

#import "RHMessageViewController.h"
#import "RHLoginViewController.h"
#import "RHMessageListController.h"
#import "RHMessageCell.h"

@interface RHMessageViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) UIView *headerView;

@property (nonatomic ,strong) UIView *footerView;




@end

@implementation RHMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = CFTabViewBgColor;
    self.navigationItem.title = @"Message";
    [self setupUI];
}


- (void)setupUI{
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView registerClass:[RHMessageCell class] forCellReuseIdentifier:@"RHMessageCell"];
    [self.view addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, kUI_WINDOW_W*0.4)];
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor whiteColor];
    [header addSubview:bgView];
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    QMUIButton *userInfoBtn = [[QMUIButton alloc]init];
    [bgView addSubview:userInfoBtn];
    [userInfoBtn setTitle:@"User Information" forState:UIControlStateNormal];
    [userInfoBtn setTitleColor:kCOLOR_HEX(@"3F4443") forState:UIControlStateNormal];
    [userInfoBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [userInfoBtn setImagePosition:QMUIButtonImagePositionTop];
    
    
    header.backgroundColor = [UIColor clearColor];
    _tableView.tableHeaderView = header;
}

- (UIView *)footerView{
    if(!_footerView){
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,300)];
        [_footerView setBackgroundColor:UIColor.clearColor];
        
        UIView *view =  [[UIView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-30,200)];
        [view setBackgroundColor:UIColor.whiteColor];
        [view round:8 RectCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight];
        [_footerView addSubview:view];
    }
    return _footerView;
}

- (UIView *)headerView{
    if(!_headerView){
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,30)];
        [_headerView setBackgroundColor:UIColor.clearColor];
        
        UIView *view =  [[UIView alloc] initWithFrame:CGRectMake(15, 20, SCREEN_WIDTH-30,10)];
        [view setBackgroundColor:UIColor.whiteColor];
        [view round:8 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
        [_headerView addSubview:view];
    }
    return _headerView;
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return self.headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 300;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
   return self.footerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    RHMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHMessageCell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    NSArray *titles = @[@"fault message",@"service information",@"notification message",@"dynamic information"];
    NSArray *icons = @[@"msg_fault",@"msg_sever",@"msg_notic",@"msg_dy"];
    //[cell setTitleStr:titles[indexPath.row]];
    //[cell setContentStr:contents[indexPath.row]];
    [cell setIconStr:icons[indexPath.row]];
    [cell setTitleStr:titles[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    RHMessageListController *vc = [[RHMessageListController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}



@end
